package pkg

import (
	"api/basic/config"
	"github.com/google/uuid"
	"github.com/hashicorp/consul/api"
)

type Consul struct {
	Host string
	Port int
}

func NewConsul(host string, port int) *Consul {
	return &Consul{
		Host: host,
		Port: port,
	}
}

func RegisterService(name, host string, port int, tags []string) error {
	ss := &api.AgentServiceRegistration{
		ID:      uuid.NewString(),
		Name:    name,
		Tags:    tags,
		Port:    port,
		Address: host,
	}
	err := config.Consul.Agent().ServiceRegister(ss)
	if err != nil {
		return err
	}
	return nil
}
